package com.qfedu.knowledge.controller;

import com.qfedu.knowledge.entity.dto.AddNoteDTO;
import com.qfedu.knowledge.entity.dto.BasePageDTO;
import com.qfedu.knowledge.entity.dto.QueryDTO;
import com.qfedu.knowledge.entity.dto.QuestionInfoDTO;
import com.qfedu.knowledge.entity.vo.ResultVO;
import com.qfedu.knowledge.service.IQuestionInfoService;
import com.qfedu.knowledge.service.IQuestionNoteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName QuestionInfoController
 * @Author ykx
 * @Date 2024/1/4 9:46
 * @Version 1.0
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/knowledge")
public class QuestionInfoController {

    @Autowired
    private IQuestionInfoService questionInfoService;

    @Autowired
    private IQuestionNoteService questionNoteService;


    @PostMapping("/getQuestionInfoByPage")
    public ResultVO getQuestionInfoByPage(BasePageDTO basePageDTO, @RequestBody QueryDTO queryDTO) {
        return ResultVO.success(questionInfoService.getQuestionInfoByPage(basePageDTO, queryDTO));
    }

    @PostMapping("/addQuestion")
    public ResultVO addQuestion(@Validated @RequestBody QuestionInfoDTO questionInfoDTO) {
        return ResultVO.success(questionInfoService.addQuestion(questionInfoDTO));
    }

    @GetMapping("/getBaseInfoById/{id}")
    public ResultVO getBaseInfoById(@PathVariable Long id) {
        return ResultVO.success(questionInfoService.getBaseInfoById(id));
    }

    @PostMapping("/updQuestionInfo")
    public ResultVO updQuestionInfo(@RequestBody QuestionInfoDTO questionInfoDTO) {
        return ResultVO.success(questionInfoService.updQuestionInfo(questionInfoDTO));
    }

    @PostMapping("/note/add")
    public ResultVO addNote(@RequestBody AddNoteDTO addNoteDTO) {
        return ResultVO.success(questionNoteService.takeNote(addNoteDTO));
    }

    @GetMapping("/note/list/{questionId}")
    public ResultVO getNodeList(@PathVariable Long questionId, BasePageDTO basePageDTO) {
        return ResultVO.success(questionNoteService.getNodeList(questionId, basePageDTO));
    }

    @DeleteMapping("/note/{id}")
    public ResultVO deleteNode(@PathVariable Long id) {
        return ResultVO.success(questionNoteService.removeById(id));
    }

}
